package modules
{
	import asf.sections.Section;
	import asf.views.View;
	
	import br.com.stimuli.string.printf;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.utils.getQualifiedClassName;
	
	import sample.app.Globals;
	import sample.components.MyButton;

	public class SectionView1 extends View
	{
		private var bt1:MyButton;
		private var bt2:MyButton;
		
		public function SectionView1( p_section:Section )
		{
			super( p_section );
			
			graphics.beginFill( 0xFF0000 );
			graphics.drawRect( 0, 0, 600, 400 );
			
			addEventListener( Event.ADDED_TO_STAGE, added, false, 0, true );
			
		}
		
		private function added( evt:Event ):void
		{
			addEventListener( Event.ADDED_TO_STAGE, added );
			
			ctrace( section._.title, section._.menu.item1 );
			ctrace( section._.message );
			
			ctrace( ">> ", section.parameters.teste );
			ctrace( ">> ", section.parameters.someParam );
			ctrace( ">> ", section.parameters.inside1 );
			ctrace( ">> ", section.parameters.inside2 );
			ctrace( ">> ", section.parameters.inside3 );
			ctrace( ">> ", section.parameters.getParam( "cond" ) );
			
			bt1 = new MyButton( printf( section._.buttons.pop, 1 ) );
			bt2 = new MyButton( printf( section._.buttons.pop, 2 ) );
			
			bt1.x = 40;
			bt1.y = 50;
			
			bt2.x = bt1.x;
			bt2.y = bt1.y + bt1.height + 10;
			
			addChild( bt1 );
			addChild( bt2 );
			
			bt1.addEventListener( MouseEvent.CLICK, pop1Click );
			bt2.addEventListener( MouseEvent.CLICK, pop2Click );
		}
		
		private function pop1Click( evt:MouseEvent ):void
		{
			section.application.popups.openPopup( Globals.POPS_POP1 ); 
		}
		
		private function pop2Click( evt:MouseEvent ):void
		{
			section.application.popups.openPopup( Globals.POPS_POP2 );
		}
		
		public override function dispose( ):void
		{
			super.dispose( );
			
			bt1.removeEventListener( MouseEvent.CLICK, pop1Click );
			bt2.removeEventListener( MouseEvent.CLICK, pop2Click );
			
			removeChild( bt1 );
			removeChild( bt2 );
			
			bt1 = null;
			bt2 = null;
			
		}
	}
}
